package com.bingluo.ui;

import java.util.ArrayList;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class EditTag extends Activity {

	private static final ArrayList<String> sp_init_data = new ArrayList<String>();
	
	private ArrayAdapter<String> adapter;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.edit_tag);

		String music_title = (String) getIntent().getExtras()
				.get("music_title");
		EditText et_music_title = (EditText) this
				.findViewById(R.id.et_music_title);
		sp_init_data.add("<编辑>");
		sp_init_data.add("<blank>");
		sp_init_data.add("<keep>");
		ArrayList<String> to_sp_d1 = sp_init_data;
		et_music_title.setText(music_title);
		if (music_title != "") {
			to_sp_d1.add(music_title);
		}
		Spinner sp_music_title = (Spinner) this
				.findViewById(R.id.sp_music_title);
		// 将可选内容与ArrayAdapter连接起来
		adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, to_sp_d1);
		// 设置下拉列表的风格
		adapter
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// 将adapter 添加到spinner中
		sp_music_title.setAdapter(adapter);
		// 添加事件Spinner事件监听
		sp_music_title.setOnItemSelectedListener(new SpinnerSelectedListener());
		// 设置默认值
		sp_music_title.setVisibility(View.VISIBLE);

		String music_artist = (String) getIntent().getExtras().get(
				"music_artist");
		EditText et_music_artist = (EditText) this
				.findViewById(R.id.et_music_artist);
		et_music_artist.setText(music_artist);

		String music_album = (String) getIntent().getExtras()
				.get("music_album");
		EditText et_music_album = (EditText) this
				.findViewById(R.id.et_music_album);
		et_music_album.setText(music_album);

		String music_year = (String) getIntent().getExtras().get("music_year");
		EditText et_music_year = (EditText) this
				.findViewById(R.id.et_music_year);
		et_music_year.setText(music_year);

		String music_track = (String) getIntent().getExtras()
				.get("music_track");
		EditText et_music_track = (EditText) this
				.findViewById(R.id.et_music_track);
		et_music_track.setText(music_track);

		String music_genre = (String) getIntent().getExtras()
				.get("music_genre");
		EditText et_music_genre = (EditText) this
				.findViewById(R.id.et_music_genre);
		et_music_genre.setText(music_genre);

		String music_comment = (String) getIntent().getExtras().get(
				"music_comment");
		EditText et_music_comment = (EditText) this
				.findViewById(R.id.et_music_comment);
		et_music_comment.setText(music_comment);

		String music_album_artist = (String) getIntent().getExtras().get(
				"music_album_artist");
		EditText et_music_album_artist = (EditText) this
				.findViewById(R.id.et_music_album_artist);
		et_music_album_artist.setText(music_album_artist);

		String music_composer = (String) getIntent().getExtras().get(
				"music_composer");
		EditText et_music_composer = (EditText) this
				.findViewById(R.id.et_music_composer);
		et_music_composer.setText(music_composer);

		String music_discnumber = (String) getIntent().getExtras().get(
				"music_discnumber");
		EditText et_music_discnumber = (EditText) this
				.findViewById(R.id.et_music_discnumber);
		et_music_discnumber.setText(music_discnumber);

		Bitmap music_cover = (Bitmap) getIntent().getParcelableExtra(
				"music_cover");
		ImageView et_music_cover = (ImageView) findViewById(R.id.et_music_cover);
		et_music_cover.setImageBitmap(music_cover);

	}

	class SpinnerSelectedListener implements OnItemSelectedListener {

		@Override
		public void onItemSelected(AdapterView<?> parent, View view,
				int position, long id) {
			System.out.println("Spinner1: position=" + position + " id=" + id);
			// 选择后
		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// showToast("没有选择");
			// 没有选择
		}
	}
}
